<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>js-函数</title>
</head>
<body>

    <button onclick="hello()">点击</button>


    <script>



        // let name = prompt("请输入姓名:")


        // 普通函数

        function print(msg = 1){

            console.log(msg);

        }

        //匿名函数
        const list = [1,2,3,4,5,6]

        const forE = function (num){

            /* 变量赋值一个匿名函数 */

            print(num);

            return ++num;
        }

        print(forE.toString())


        /* 回调函数(函数用法)
        
        把函数作为一种参数,传入到函数中去执行,函数调用时回头再去调用传入的函数

        为了函数式编程服务的
        */
        list.forEach((num)=>print(num));

        list.forEach(forE)

        print(list)



        function hello(){

           let is =  confirm('你确定要执行这个操作吗？');
           
           is?alert('hello'): 1;
        }

        const data = new Date(1724309697293)

        console.log(data);

        console.log("年"+data.getFullYear());
        console.log("月"+(data.getMonth()+1));
        console.log("日"+data.getUTCDay());
        console.log("秒"+data.getSeconds());

        /* 时间戳   作为通用的时间传输格式 */
        console.log("格林"+data.getTime());

        const options = {
  weekday: 'long',
  year: 'numeric',
  month: 'long',
  day: 'numeric',
};

        console.log(data.toLocaleString(options));


        let list1 = [2,1,3,6,7,2];

        list1  =list1.filter((num)=>{
            return num%2==0;
        })

        console.log(list1);

        obj1 = {namespaced: true,age:19}

        /* 
         "{"namespaced": true,"1":19}"
        
        " [1,2,3,4,5] "
        */


        //将对象类型转为json的字符串

        console.log(new Date().get);

        //序列化
        let obj_json = JSON.stringify(obj1);

        console.log(obj_json);


        //反序列化
        //将json字符串的内容解析为js的类型
        obj1 = JSON.parse('[1,2,"ahsgd",4]')

        console.log(obj1);




    </script>
    
</body>
</html>